Remove fake borrows of refs that are converted into non-refs in MakeByMoveBody
#138514
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Remove fake borrows of closure captures if that capture has been replaced with a by-move version of that capture.
For example, given an async closure that looks like:
... in this pair of coroutine-closure + coroutine, we capture
Foo
in the parent and&Foo
in the child. We will emit two fake borrows like:However, since the by-move-body transform is responsible for replacing
_1.0: &Foo
with_1.0: Foo
(since theAsyncFnOnce
coroutine will ownFoo
by value), that makes the second fake borrow obsolete since we never have an upvar of type&Foo
, and we should replace it with anop
.As a side-note, we don't actually even care about fake borrows here at all since they're fully a MIR borrowck artifact, and we don't need to borrowck by-move MIR bodies. But it's best to preserve as much as we can between these two bodies :)
Fixes #138501
r? oli-obk